<template>
  <div class="content-box">
    <nav-title title="奖惩情况" />
    <div class="line">
      <span class="important">*</span>
      <div class="label">获得时间</div>
      <div class="value">
        <group>
          <datetime :min-year="1900" :max-year="2100" value-text-align="left" placeholder="请选择" v-model="rewds.cDate"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">奖惩类别</div>
      <div class="value">
        <group label-width="5em">
          <popup-radio placeholder="请选择" :options="rewardsList" v-model="rewds.rsJclbType"></popup-radio>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="rewds.cName">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">授权机构</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="rewds.cCompany">
      </div>
    </div>
    <div class="submit-btn" @click="save">
      保存
    </div>
    <div class="remove-btn" @click="remove">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { saveRewards,delRewards,getDicItem } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    this.getDic();
  },
  data() {
    return {
      rewds:{
        rsHireId: '',
      },
      rewdsDel:{
        rsHireId: '',
        cSeqno: ''
      },

      rewardsList: [],
      rewardsLength: 1,
      rewards: [],
    }
  },
  created() {
    this.getRwds()
    if(this.$store.state.hid){
      this.rewds.rsHireId = this.$store.state.hid
      this.rewdsDel.rsHireId = this.$store.state.hid
    }
  },
  methods: {
    getDic(){
      //掌握程度字典
      getDicItem({fileName: 'RS_JCLB_TYPE'}).then(res=>{
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.rewardsList.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
          }
        }
      }).catch(res=>{

      });
    },
    save() {
      const that = this
      if(that.rewds.cDate == ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择获得时间'
        });
        return;
      }

      if(that.rewds.rsJclbType == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择奖惩类别'
        });
        return;
      }

      if(that.rewds.cName == '' || that.rewds.cName == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入名称'
        });
        return;
      }

      saveRewards(json2Form(that.rewds)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {

      const _this = this;
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delRewards(json2Form(_this.rewds)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                _this.$vux.alert.show({
                  title: '提示',
                  content: '删除成功',
                  onHide () {
                    _this.$router.push('/informationCollection/userInfo');
                  }
                })
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })        
          }
        })
    },
    getRwds() {
      if(this.$route.params.rewd){
        this.rewds = this.$route.params.rewd
        this.rewdsDel.cSeqno = this.$route.params.rewd.cSeqno
      }

    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
</style>
